/*
 * Written by José Grimaldo         <jose.jgrimaldo@gmail.com>
 *            Adailton Cerqueira    <adailton.junior@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef LOGGER_H_
#define LOGGER_H_

#include <stdio.h>
#include <iostream>
#include <sstream>

#include "LoggerBuffer.h"

#define LOG(theLevel) \
	if (LogParameters::instance().level() > theLevel \
	   || !LogParameters::instance().active()) ; \
    else Logger().Get(theLevel)

/**
 *
 * The log levels available are:
 *  debug, info, warn and error
 *
 * each of of these levels handles
 * a specific purpose. Debug levels
 * for example are designed for simple message about variable
 * values, a little of flow tracing, etc.
 * The error level are for problems with the application that
 * will most likely result in a shutdown
 *
 */
enum log_level_t {
	log_TRACE,
	log_DEBUG,
	log_INFO,
	log_WARN,
	log_ERROR,
	log_SCRIPT,
	log_MILA,
	log_TRAINER
};


class LogParameters {
public:

	static LogParameters& instance();

	log_level_t level();
	void level(log_level_t level);

	bool active(void);
	void active(bool isActive);

private:

	LogParameters() {};
	LogParameters(const LogParameters& l);
	LogParameters& operator= (const LogParameters& l);

private:

	log_level_t m_logLevel;
	bool 		m_active;
};


class Logger {
public:

	Logger();
	~Logger();

	std::ostream& Get(log_level_t level = log_DEBUG);

private:

	Logger(const Logger& l);
	Logger& operator= (const Logger& l);

private:

	std::ostringstream m_buffer;
	log_level_t        m_logLevel;
};

#endif /* LOGGER_H_ */
